//
//  CityNearCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/6/4.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "CityNearCell.h"
#import "NearRecommendCell.h"
#import "RecommendMerchantDetailVC.h"
#define KcellWidth  (kScreenWidth - 40)/2

#define kcellHeight (KcellWidth /16 * 9 + 78)

@interface CityNearCell()

@property (nonatomic,strong) NSMutableArray * dataSource;

@end

@implementation CityNearCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"NearRecommendCell" bundle:nil] forCellWithReuseIdentifier:@"NearRecommendCell"];
    
    self.collectionView.scrollEnabled = NO;
    self.collectionView.backgroundColor = kBGColor;
    self.contentView.backgroundColor = kBGColor;
}


- (void)setMerchantArray:(NSArray *)merchantArray {
    
    _merchantArray = merchantArray;
    
    NSInteger num = ceil(merchantArray.count / 2.0);
    
    self.collectionViewHeight.constant = kcellHeight * num  + (num - 1) * 10;
    
    [self.collectionView reloadData];
}

#pragma mark   -- UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.merchantArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MerchantModel *model = self.merchantArray[indexPath.row];
    
    NearRecommendCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NearRecommendCell" forIndexPath:indexPath];
    cell.model = model;
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    MerchantModel *model = self.merchantArray[indexPath.row];
    
    RecommendMerchantDetailVC * vc = [[RecommendMerchantDetailVC alloc] init];
     vc.hidesBottomBarWhenPushed = YES;
    vc.model = model;
    [self.superVC.navigationController pushViewController:vc animated:YES];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return  CGSizeMake(KcellWidth, kcellHeight);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(0, 5, 0, 5);
}
@end
